import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, SaveExcelButton, CommonButton } from '../Common/options'
import { MachineTypeTree } from '../Common/Conversion'

export const Machine = async ({ url, OptionsEvent, ClientData, Permission }) => {
    Permission = Permission?.find(v => v.targetUrl === url).children
    const parentUuid = await MachineTypeTree()
    const { hostname } = window.location
    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission?.findIndex(v => v.uuid === '145df9f6-1702-40ff-8f20-8411a62b936c') !== -1 && (
                <SaveExcelButton key="excel" title="Excel导出" api={API_LIST()['getMachineExcel']} />
            ),
            Permission?.findIndex(v => v.uuid === 'cd4b43ba-bccb-4f7f-af0e-718ae750ffed') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} url={url} type="primary" icon="add" title="新增机械信息" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.SearchSort, selectType: 'Machine' },
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },

            {
                dataIndex: 'machineTypeUuid',
                title: '机械类别',
                valueType: 'treeSelect',
                fieldProps: {
                    options: parentUuid,
                    fieldNames: { label: 'tableName', value: 'uuid' },
                },
                rules: true,
                width: 150,
                hideInSearch: true,
            },
            { ...commonTableList.code, title: '进厂编号', rules: true, hideInSearch: true },
            { ...commonTableList.tableName, title: '机械名称' },
            {
                dataIndex: 'brand',
                valueType: 'input',
                title: '品牌',
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'manufactureDate',
                title: '生产日期',
                valueType: 'Date',
                showTime: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'ownerName',
                title: '车主姓名',
                valueType: 'input',
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'ownerMobile',
                title: '车主电话',
                valueType: 'inputNumber',
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'driverName',
                title: '司机姓名',
                valueType: 'input',
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'driverIdentityCard',
                title: '司机身份证',
                valueType: 'input',
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'driverMobile',
                title: '司机电话',
                valueType: 'inputNumber',
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'entryTime',
                title: '进场时间',
                valueType: 'Date',
                showTime: true,
                rules: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'leaveTime',
                title: '退场时间',
                valueType: 'Date',
                showTime: true,
                width: 200,
                hideInSearch: true,
            },

            {
                dataIndex: 'durableYears',
                title: '使用年限',
                valueType: 'input',
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'gpsDeviceSerial',
                title: 'Gps设备序列号',
                valueType: 'input',
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'cameraName',
                title: '摄像头名称',
                valueType: 'hidden',
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'carNumber',
                title: '车牌号',
                valueType: 'input',
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'cardNumber',
                title: '卡号',
                valueType: 'input',
                width: 150,
                hideInSearch: true,
            },
            commonTableList.BeginEntryTime,
            commonTableList.EndEntryTime,
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 240,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        hostname === 'jtgj.ljkjkf.com' && (
                            <CommonButton
                                key="submit"
                                OptionsEvent={OptionsEvent}
                                title="机械档案"
                                data={{
                                    type: 'FileManagement',
                                    classification: 'machine',
                                    record,
                                    width: 1000,
                                }}
                            />
                        ),

                        Permission.findIndex(v => v.uuid === '22c562b9-1563-4087-8b5d-950a2b456266') !== -1 && (
                            <ModDataButton
                                OptionsEvent={OptionsEvent}
                                key="modify"
                                title="修改"
                                url={url}
                                data={record}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === 'c0a5f585-adaf-475e-b526-91a0a0af8012') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
